const colorRed="#BC2B37"
const colorGreen="#029B5A"
const _colorUp=uni.getStorageSync("colorUp")
//用户模块
export default {
	namespaced: true,
	state: {
		isMock:false,
		userInfo:"",
		mockUserInfo:"",
		colorUp:_colorUp||"red"
	},
	getters:{
		getUpColor(state,getters){
			return getters.getColorUp=="red"?colorRed:colorGreen
		},
		getDownColor(state,getters){
			return getters.getColorUp=="red"?colorGreen:colorRed
		},
		getColorUp(state){
			return state.colorUp
		},
		getUserInfo(state){
			if(state.isMock){
				return state.mockUserInfo
			}
			else{
				const userInfo=uni.getStorageSync("userInfo")
				let _userInfo
				if(userInfo){
					_userInfo=JSON.parse(userInfo)
				}
				return state.userInfo||_userInfo
			}
		},
		getToken(state,getters){
				if(getters.getUserInfo){
					return getters.getUserInfo.token
				}
				return undefined
			
		},
	},
	mutations: {
		modifyColorUp(state,payload){
			state.colorUp=payload
			uni.setStorageSync("colorUp",payload)
		},
		modifyMockUserInfo(state, payload) {
			state.mockUserInfo = payload;
		},
		modifyIsMock(state,payload){
			state.isMock=payload
		},
		modifyUserInfo(state,payload){
			state.userInfo=payload
			uni.setStorageSync("userInfo",JSON.stringify(payload))
		},
		logout(state,payload){
			this.commit("user/modifyUserInfo",{})
			this.commit("user/modifyMockUserInfo",{})
			this.commit("user/modifyIsMock",false)
		}
	},
}